package config

import (
	"os"
	"fmt"
	"git.oschina.net/YPTArch/basic/sys/logs"
)

/*var(
	DataBaseConnectionString string="root:abcd1234@tcp(192.168.1.235:3306)/UserCenter?charset=utf8" //数据库连接字符串
	HttpPort string ="11020" //http端口
	AppConnAddress string="192.168.1.234:11000" //app连接地址
	AuthConnAddress string="192.168.1.234:11010" //auth连接地址
	ApiGatewayAddress string="192.168.1.234:8081" //api网关连接地址
	RedisAddress string ="192.168.1.235:6379"	//redis 地址
	RedisPwd string="root"	//redis密码
	RedisDBIndex string ="5" //redis 数据库
)*/
var(
	DataBaseConnectionString string="root:abcd1234@tcp(42.123.126.178:3306)/UserCenter?charset=utf8" //数据库连接字符串
	HttpPort string ="9102" //http端口
	AppConnAddress string="42.123.127.83:9104" //app连接地址
	AuthConnAddress string="42.123.127.83:9107" //auth连接地址
	ApiGatewayAddress string="42.123.127.83:9001" //api网关连接地址
	RedisAddress string ="42.123.127.83:6379"	//redis 地址
	RedisPwd string="root"	//redis密码
	RedisDBIndex string ="5" //redis 数据库
)



func init() {
	logs.Logger.Info("----------加载系统环境变量----------")
	err:= LoadSysConfig()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(2)
	}
	logs.Logger.Info("----------系统环境变量----------")
	logs.Logger.Info("DataBaseConnectionString=>"+GetDataBaseConnectionString())
	logs.Logger.Info("HttpPort=>"+GetHttpPort())
	logs.Logger.Info("AppConnAddress=>"+GetAppConnAddress())
	logs.Logger.Info("AuthConnAddress=>"+GetAuthConnAddress())
	logs.Logger.Info("ApiGatewayAddress=>"+GetApiGatewayAddress())
	logs.Logger.Info("RedisAddress=>"+GetRedisAddress())
	logs.Logger.Info("RedisPwd=>"+GetRedisPwd())
	logs.Logger.Info("RedisDBIndex=>"+GetRedisDBIndex())
	logs.Logger.Info("----------系统环境变量----------")
}

func LoadSysConfig() (error) {
	if os.Getenv("DataBaseConnectionString")!=""{
		DataBaseConnectionString=os.Getenv("DataBaseConnectionString")
	}
	if os.Getenv("HttpPort")!=""{
		HttpPort=os.Getenv("HttpPort")
	}
	if os.Getenv("AppConnAddress")!=""{
		AppConnAddress=os.Getenv("AppConnAddress")
	}
	if os.Getenv("AuthConnAddress")!=""{
		AuthConnAddress=os.Getenv("AuthConnAddress")
	}
	if os.Getenv("ApiGatewayAddress")!=""{
		ApiGatewayAddress=os.Getenv("ApiGatewayAddress")
	}
	if os.Getenv("RedisAddress")!=""{
		RedisAddress=os.Getenv("RedisAddress")
	}
	if os.Getenv("RedisPwd")!=""{
		RedisPwd=os.Getenv("RedisPwd")
	}
	if os.Getenv("RedisDBIndex")!=""{
		RedisDBIndex=os.Getenv("RedisDBIndex")
	}
	return nil
}
func GetDataBaseConnectionString() string {
	return DataBaseConnectionString
}
func GetHttpPort() string {
	return HttpPort
}

func GetAuthConnAddress() string {
	return AuthConnAddress
}

func GetAppConnAddress() string {
	return AppConnAddress
}
func GetApiGatewayAddress() string {
	return ApiGatewayAddress
}
func GetRedisAddress() string {
	return RedisAddress
}

func GetRedisPwd() string {
	return RedisPwd
}

func GetRedisDBIndex() string {
	return RedisDBIndex
}